
#include <BNode>
#include <BWidget>

#include <BMoveChannel>
#include "member_BMoveChannel.h"

using namespace BWE;

#define member					(*(member_BMoveChannel*)_ptr)
#define member_allocate()		_ptr = new member_BMoveChannel(this)
#define member_release()		delete (member_BMoveChannel*)_ptr

BMoveChannel::BMoveChannel()
{
	member_allocate();
	this->setLerp(Lerp_Linear);
}
BMoveChannel::BMoveChannel(const BString& name, const BString& targetName)
{
	member_allocate();
	this->setName(name);
	this->setTargetName(targetName);
	this->setLerp(Lerp_Linear);
}
BMoveChannel::~BMoveChannel()
{
	member_release();
}

bool BMoveChannel::insertKeyframe(float time, const BVector& vector)
{
	int pos = member.sampler->indexOf(member.keyframes, time);
	return member.keyframes.insert(pos, BVectorKeyframe(time, vector));
}
bool BMoveChannel::insertKeyframe(const BVectorKeyframe& keyframe)
{
	int pos = member.sampler->indexOf(member.keyframes, keyframe.time());
	return member.keyframes.insert(pos, keyframe);
}
bool BMoveChannel::removeKeyframe(int index)
{
	return member.keyframes.remove(index);
}

bool BMoveChannel::insertKeyframe(float time)
{
	BVector vector = member.sampler->lerp(member.keyframes, time);
	int pos = member.sampler->indexOf(member.keyframes, time);
	return member.keyframes.insert(pos, BVectorKeyframe(time, vector));
}
bool BMoveChannel::removeKeyframe(float time)
{
	for (int i = 0; i < member.keyframes.size(); i++)
	{
		if (member.keyframes[i].time() == time)
		{
			member.keyframes.remove(i);
			return true;
		}
	}
	return false;
}

int BMoveChannel::keyframeCount() const
{
	return member.keyframes.size();
}
BKeyframe& BMoveChannel::keyframe(int index)
{
	return member.keyframes(index);
}

bool BMoveChannel::accept(BObject* object)
{
	BNode* node = dynamic_cast<BNode*>(object);
	if (node)
		return true;
	BWidget* widget = dynamic_cast<BWidget*>(object);
	if (widget)
		return true;
	return false;
}
void BMoveChannel::apply(BObject* object)
{

}
void BMoveChannel::update(double time)
{

}
